package com.ruoyi.radar.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.radar.domain.RadarSilo;
import com.ruoyi.radar.domain.RadarSiloConf;
import com.ruoyi.radar.service.RadarSiloConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//
@CrossOrigin
@RestController
@RequestMapping("/radarSiloConf")
public class RadarSiloConfController extends BaseController {
    @Autowired
    private RadarSiloConfService radarSiloConfService;
///radarSilo/add

    /**
     * 获取料仓模型列表
     */
    @PreAuthorize("@ss.hasPermi('radarSilo:siloConf:list')")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam Map<String, Object> param)
//    public TableDataInfo list(GnssEquip equip)
    {
//        startPage();
        Map<String, Object> result = new HashMap<>(2);
//        Map<String, Object> gnssMap = radarSiloService.selectSiloList(param);
        List<RadarSiloConf> radarSiloConfs = radarSiloConfService.selectSiloConfList(param);
        Integer count = radarSiloConfService.getCount(param);
        result.put("data", radarSiloConfs);
        result.put("total", count);
        return AjaxResult.success(result);
    }


    /**
     * 新增料仓模型
     */
    @PreAuthorize("@ss.hasPermi('radarSilo:siloConf:add')")
    @PostMapping
    @Log(title = "料仓设置", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody RadarSiloConf radarSiloConf)
    {
        radarSiloConf.setSiloConfId(uuId());
        radarSiloConf.setCreateTime(currentTime());
        radarSiloConf.setUpdateTime(currentTime());

//        GnssEquip gnssEquip = new GnssEquip();


        return toAjax(radarSiloConfService.save(radarSiloConf));
//        return success(radarSilo);
    }

    /**
     *修改料仓模型
     */
    @PreAuthorize("@ss.hasPermi('radarSilo:siloConf:update')")
    @Log(title = "修改料仓", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody RadarSiloConf radarSiloConf)
    {
        try{
            radarSiloConf.setUpdateTime(currentTime());
            return toAjax(radarSiloConfService.updateById(radarSiloConf));
        }catch (Exception e){
            return AjaxResult.success("操作失败");
        }
    }

    /**
     *修改料仓模型
     */
    @PreAuthorize("@ss.hasPermi('radarSilo:siloConf:delete')")
    @Log(title = "删除料仓", businessType = BusinessType.DELETE)
    @DeleteMapping("/{siloConfId}")
    public AjaxResult delete(@PathVariable String siloConfId)
    {
        try{

            return toAjax(radarSiloConfService.removeById(siloConfId));
        }catch (Exception e){
            return AjaxResult.success("操作失败");
        }
    }

}